package com.yoso.shop.interfaces.controller.commodity;

import com.yoso.base.interfaces.controller.BaseController;
import com.yoso.base.interfaces.controller.BaseResponse;
import com.yoso.base.service.BaseEntityExample;
import com.yoso.base.service.IBaseService;
import com.yoso.shop.application.service.IDictionaryService;
import com.yoso.shop.domain.dictionary.DictionaryEntity;
import com.yoso.shop.interfaces.vo.dictionary.DictionaryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yoso
 * @date 2022/2/20
 */
@RequestMapping("dictionary")
@RestController
@Api(tags = "数据字典")
@Slf4j
@CrossOrigin
public class DictionaryController extends BaseController<DictionaryVo, DictionaryEntity> {
    @Autowired
    private IDictionaryService dictionaryService;

    @PostMapping("getDataByGroup")
    @ApiOperation("获取指定分组数据")
    public BaseResponse getDataByGroup(String group) {
        return this.success(this.dictionaryService.getDataByGroup(group));
    }

    @GetMapping("getData")
    @ApiOperation("获取轮播图，热词，新闻数据")
    public BaseResponse getData() {
        return this.success(this.dictionaryService.getData());
    }

    @Override
    public DictionaryEntity V2E(DictionaryVo data) {
        return this.convert(data, DictionaryEntity.class);
    }

    @Override
    public DictionaryVo E2V(DictionaryEntity data) {
        return this.convert(data, DictionaryVo.class);
    }

    @Override
    public IBaseService<DictionaryVo, ? extends BaseEntityExample> getService() {
        return dictionaryService;
    }
}
